//
//  BundleUtil.m
//  SWIOSLibary
//
//  Created by shaowei on 13-7-19.
//  Copyright (c) 2013年 LianZhan. All rights reserved.
//

#import "SWBundleUtil.h"

@implementation SWBundleUtil

+ (NSString *)pathForResource:(NSString *)resName ofType:(BundleResourceType)type{
    NSString *resPath = [[NSBundle mainBundle] resourcePath];
    NSString *bundlePath = [resPath stringByAppendingPathComponent:@"SWIOSLibary.bundle"];
    NSString *typePath = nil;
    
    switch (type) {
        case BundleResourceOfImage:{
            typePath =@"images";
        }
            break;
        case BundleResourceOfFile:{
            typePath =@"files";
        }
            break;
        case BundleResourceOfMedia:{
            typePath =@"media";
        }
            break;
            
        default:
            SWASSERT_SWITCH_OVER;
            break;
    }
    
    NSString *resultPath = [[bundlePath stringByAppendingPathComponent:typePath]
                            stringByAppendingPathComponent:resName];
    
    if (![[NSFileManager defaultManager] fileExistsAtPath:resPath]) {
        //文件不存在
        resultPath = nil;
    }
    
    return resultPath;
    
}

@end
